<template>
	<view class="pages">
		<!-- 头部导航 -->
		<uni-nav-bar left-icon="left"    :statusBar="true" titleSize="30px" leftText="返回"   title="物流管理"  @clickLeft="back"   :fixed="true" backgroundColor="#3286ed" color="#fff"/>
	     <view style="border-bottom:1px solid #ccc ;margin: 5px;">
	     	  <u-tabs @click="clickFn"  lineWidth="200rpx" lineColor="#49b2f1" :list="list":activeStyle="{ transform: 'scale(1.05)'}"></u-tabs>
	     </view>
		 <view v-if="Index==0" class="">
		 	<!-- 出库单 -->
			<view   v-for="(item,index) in outList" class="application" :key="index">
				<view class="list-out" @click="toaddOutinfo(item)" >
					   <view class="list-top">
						   <view class="title">出库编号:{{item.outboundNo}}</view>
						   
						   <view class="status">
							<view v-if="item.orderStatus=='1'">待出库</view>
							<view v-if="item.orderStatus=='2'">已出库</view>
						   </view>
						   <view class="status">
						   	<view v-if="item.expensesStatus=='1'">物流已完成</view>
						   	<view v-if="item.expensesStatus=='2'">物流未完成</view>
						   </view>
					   </view>
					   <view class="list-body">
						   <view>订单:<span>{{item.orderNo}}</span></view>
							<view>出库时间:<span>{{item.outboundTime}}</span></view>
							<view>客户名称:<span>{{item.customerName}}</span></view>
							<view>发起人:<span>{{item.sponsorName}}</span></view>
							<view v-if="item.orderType==1">订单类型:<span>租赁</span></view>
							<view v-if="item.orderType==2">订单类型:<span>售卖</span></view>
							<view>出库仓库:<span>{{item.outboundWarehouseName}}</span></view>
					   </view>
				 </view>
			</view>
	
		 </view>
		 
		 <!-- 回货申请单 -->
		 <view v-if="Index==1"  >
		 	<view class="application" v-for="(item,index) in backList" :key="index" @click="tobackInfo(item)">
				<view class="application_one">{{item.returnApplyNo}}</view>
				<view class="desc">租赁销售订单：{{item.orderNo}}</view>
				<view class="desc">客户名称：{{item.customerName}}</view>
				<view  class="desc">发起人： {{item.sponsorName}} </view>
				<view class="desc">
					<view>
						<span>回货类型：</span>
						<span v-if="item.returnType==1">回货</span>
						<span v-if="item.returnType==2">退货</span>
					</view>
					<view>
						<span>物流状态：</span>
						<span style="color:#fdb644;" v-if="item.expensesStatus==1">物流已完成</span>
						<span style="color:#fdb644;" v-if="item.expensesStatus==2">物流未完成</span>
					</view>
					
				</view>
				
		 	</view>
			
		 </view>
		 <!-- 出库物流费未填写 -->
		 <view v-if="Index==2" class="">
		 	<!-- 出库单 -->
		 	<view   v-for="item in outMoney" class="application">
		 		<view class="list-out" @click="toaddOutinfo(item)" >
		 			   <view class="list-top">
		 				   <view class="title">出库编号:{{item.outboundNo}}</view>
		 				   <view class="status">
		 					<view v-if="item.orderStatus=='1'">待出库</view>
		 					<view v-if="item.orderStatus=='2'">已出库</view>
		 				   </view>
		 				   <view class="status">
		 				   	<view v-if="item.expensesStatus=='1'">物流已完成</view>
		 				   	<view v-if="item.expensesStatus=='2'">物流未完成</view>
		 				   </view>
		 			   </view>
		 			   <view class="list-body">
						   <view>订单:<span>{{item.orderNo}}</span></view>
		 					<view>出库时间:<span>{{item.outboundTime}}</span></view>
		 					<view>客户名称:<span>{{item.customerName}}</span></view>
							<view>发起人:<span>{{item.sponsorName}}</span></view>
		 					<view v-if="item.orderType==1">订单类型:<span>租赁</span></view>
		 					<view v-if="item.orderType==2">订单类型:<span>售卖</span></view>
		 					<view>出库仓库:<span>{{item.outboundWarehouseName}}</span></view>
		 			   </view>
		 		 </view>
		 	</view>
		 </view>
	<view v-if="Index==3" class="">
		<view class="application" v-for="(item,index) in backmoney" :key="index" >
			<view class=""@click="tobackInfo(item)">
				<view class="application_one">{{item.returnApplyNo}}</view>
				<view class="desc">租赁销售订单：{{item.orderNo}}</view>
				<view class="desc">客户名称：{{item.customerName}}</view>
				<view class="desc">
					<view>
						<span>回货类型：</span>
						<span v-if="item.returnType==1">回货</span>
						<span v-if="item.returnType==2">退货</span>
					</view>
					<view>
						<span>物流状态：</span>
						<span style="color:#fdb644;" v-if="item.expensesStatus==1">物流已完成</span>
						<span style="color:#fdb644;" v-if="item.expensesStatus==2">物流未完成</span>
					</view>
					
				</view>
			</view>
		
			
		</view>
	</view>
	<view  v-if="Index==4"class="">
		<view v-for="(item,index) in tranferList" @click="totranferInfo(item)" style="overflow:hidden;background-color: #f2f2f2;">
			<view style="padding: 10px;height: 150px;margin-top: 10px;background-color: #fff;position: relative">
				<view style="padding-bottom: 10px;" class="">
					调拨单号：<span style="font-size: 16px;">{{item.serialNum}}</span>
				</view>
					<view style="padding-bottom: 10px;" class="">
						调拨日期：<span style="font-size: 16px;">{{item.repTransferDate}}</span>
					</view>
					<view style="padding-bottom: 10px;" class="">
						调出仓库：<span style="font-size: 16px;">{{item.outRepertory}}</span>
					</view>
					<view style="padding-bottom: 10px;" class="">
						调入仓库：<span style="font-size: 16px;">{{item.inRepertory}}</span>
					</view>
					<view class="item" style="position:absolute;right: 20px;top:10px">
						
							<span v-if="item.logisticsStatus=='0'" style="color:#fd9540;" >物流未完成</span>
							<span v-if="item.logisticsStatus=='1'" style="color:#f5f5f5;"> 物流已完成</span>
					</view>
			</view>
		</view>
	</view>
	<view  v-if="Index==5"class="">
		<view v-for="(item,index) in tranferMoney" @click="totranferInfo(item)" style="overflow:hidden;background-color: #f2f2f2;">
			<view style="padding: 10px;height: 150px;margin-top: 10px;background-color: #fff;position: relative">
				<view style="padding-bottom: 10px;" class="">
					调拨单号：<span style="font-size: 16px;">{{item.serialNum}}</span>
				</view>
					<view style="padding-bottom: 10px;" class="">
						调拨日期：<span style="font-size: 16px;">{{item.repTransferDate}}</span>
					</view>
					<view style="padding-bottom: 10px;" class="">
						调出仓库：<span style="font-size: 16px;">{{item.outRepertory}}</span>
					</view>
					<view style="padding-bottom: 10px;" class="">
						调入仓库：<span style="font-size: 16px;">{{item.inRepertory}}</span>
					</view>
					<view class="item" style="position:absolute;right: 20px;top:10px">
						
							<span v-if="item.logisticsStatus=='0'" style="color:#fd9540;" >物流未完成</span>
							<span v-if="item.logisticsStatus=='1'" style="color:#f5f5f5;"> 物流已完成</span>
					</view>
			</view>
		</view>
	</view>
	<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {listHouse,} from '@/api/out/out.js'
	import {getBackWarehouseList} from '@/api/backapplication.js'
	import{getLogisticsListApi,getoutmoneyApi,getBackmoneyApi,getTranferMoney} from"@/api/logistics.js"
	import {listTransfer} from '@/api/tranfer.js'
	export default {
		data() {
			return {
				list:[
					{
					name: '出库物流未完成',
					badge: {
					     value: 0,
					   }
					},
					{
					 name: '回货物流未完成',
					 badge: {
					      value: 0,
					    }
					},
					{
					 name: '出库物流费未填写',
					 badge: {
					      value: 0,
					    }
					},
					{
					 name: '回货物流费未填写',
					 badge: {
					      value: 0,
					    }
						},
					{
						 name: '调拨物流未填写',
						 badge: {
						      value: 0,
						    }
					},
					{
						 name: '调拨物流费未填写',
						 badge: {
						      value: 0,
						    }
					},
					{
						 name: '全部',
						 badge: {
						      value: 0,
						    }
					},
				],
				outList:[],
				outform:{
					
				},
				backList:[],
				outMoney:[],
				backmoney:[],
				tranferList:[],
				tranferMoney:[],
				Index:0,
				pageNum:1,
				pageSize:10,
				total:0
			};
		},
		onLoad() {
			
		},
		created() {
			this.getOutlist()
			this.getBackList()
			this.getOutmoneyList()
			this.getBackMoney()
			this.gettranfer()
			this.getTranferMoney()
		},
		onReachBottom(){
			if(this.Index==0){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					listHouse({expensesStatus:'2',pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.outList.push(...res.rows)
						 
					})
				}else{
					this.$refs.uToast.show({
						type:"warning",
						message:'别划了，到底了'
					})
				}
			}else if(this.Index==1){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					getBackWarehouseList({expensesStatus:'2',pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.backList.push(...res.rows)
					 
					})
				}else{
					 this.$refs.uToast.show({
						type:"warning",
						message:'别划了，我是有底线的'
					})
					
				}
				
			}else if(this.Index==2){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					getoutmoneyApi({pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.outMoney.push(...res.rows)
						 
					})
					}else{
						this.$refs.uToast.show({
							type:"warning",
							message:'别划了，我是有底线的'
						})
					}
			}else if(this.Index==3){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					getBackmoneyApi({pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.backmoney.push(...res.rows)
						 
					})
					}else{
						this.$refs.uToast.show({
							type:"warning",
							message:'别划了，我是有底线的'
						})
					}
			}else if(this.Index==4){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					listTransfer({logisticsStatus:'0',pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.tranferMoney.push(...res.rows)
						 
					})
					}else{
						this.$refs.uToast.show({
							type:"warning",
							message:'别划了，我是有底线的'
						})
					}
			}else if(this.Index==5){
				if(this.pageSize * this.pageNum < this.total){
					this.pageNum++
					getTranferMoney({ pageNum:this.pageNum,pageSize:this.pageSize}).then(res=>{
						this.tranferList.push(...res.rows)
						 
					})
					}else{
						this.$refs.uToast.show({
							type:"warning",
							message:'别划了，我是有底线的'
						})
					}
			}
		},
		onPullDownRefresh() {
		     this.getOutlist()
		     this.getBackList()
		     this.getOutmoneyList()
		     this.getBackMoney()
		     this.gettranfer()
		     this.getTranferMoney()
		    setTimeout(() => {
				 
		        uni.stopPullDownRefresh()
		    }, 2000)
		},
		methods:{
			clickFn(val){
				console.log(val);
			 this.Index=val.index
			 console.log(this.Index);
				if(this.Index==0){
					this.getOutlist()
				}
				if(this.Index==1){
					this.getBackList()
				}
				if(this.Index==2){
					this.getOutmoneyList()
				}
				if(this.Index==3){
					this.getBackMoney()
				}
				if(this.Index==4){
					this.gettranfer()
				}
				if(this.Index==5){
					this.getTranferMoney()
				}
				if(this.Index==6){
					uni.navigateTo({
						url:"/pages/logistics/index"
					})
				}
			},
			
		// 获取出库单
		  async  getOutlist(){
				let res= await listHouse({expensesStatus:'2',pageNum:this.pageNum,pageSize:this.pageSize})
				this.outList=res.rows
				this.list[0].badge.value=res.total
				this.total=res.total
			},	
			// 物流详情
			toaddOutinfo(val){
				uni.navigateTo({
					url:'/pages/logistic/addlogic/addlogic?id='+val.id
				})
			},
			// 获取出库物流费未填写
			async getOutmoneyList(){
				let res=await getoutmoneyApi()
				this.outMoney=res.rows
				this.list[2].badge.value=res.total
				this.total=res.total
			},
			// 获取回货申请单
		   async getBackList(){
						let res= await getBackWarehouseList({expensesStatus:'2',pageNum:this.pageNum,pageSize:this.pageSize})
						this.backList=res.rows
						this.list[1].badge.value=res.total
						this.total=res.total
					},
					
			// 回货申请物流费未填写
			async getBackMoney(){
				let res= await getBackmoneyApi()
				this.backmoney=res.rows
				this.total=res.total
				this.list[3].badge.value=res.total
			},
				tobackInfo(val){
					uni.navigateTo({
						url:"/pages/backapplication/backapplicationChildren/backapplicationChildren?returnApplyNo="+val.returnApplyNo
					})
				},	
					// 获取调拨物流未填写
				async gettranfer(){
					let res=await listTransfer({logisticsStatus:'0',pageNum:this.pageNum,pageSize:this.pageSize})
				     this.tranferList=res.rows
					 this.total=res.total
					 this.list[4].badge.value=res.total
				},	
				// 调拨物流费未填写
				async getTranferMoney(){
					let res=await getTranferMoney()
					this.tranferMoney=res.rows
					this.total=res.total
					this.list[5].badge.value=res.total
				},
				// 跳转到新增页面
				totranferInfo(val){
					uni.navigateTo({
						url:"/pages/logistic/addtranferlogistic/addtranferlogistic?id="+val.id
					})
				},
		//返回
			back(){
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
.pages{
	background-color: #fff;
	.application{
			  position: relative;
			  min-height: 50px;
			  padding: 10px;
			  margin: 10px 5px;
			  background-color: #fff;
			  border: solid 1px #c3c3c3;
			  .application_one{
				  font-size: 16px;
				  font-weight: 600;
				  padding-bottom: 8px;
			  }
			  .desc{
				  font-size: 12px;
				  color:#8c8b8a;
			  }
			  .addapplicaionChild{
				  position: absolute;
				  right: 20px;
				  bottom: 20px;
				  font-size: 12px;
				  color: #fd9540;
			  }
			  
	}
	.list-out{
		background-color: #fff;
		padding: 10px 10px 0px 20px;
		position: relative;
		// border-bottom: solid 1px #c3c3c3;
		.list-top{
			display: flex;
			justify-content: space-between;
			.title{
				font-size: 14px;
				font-weight: 600;
			}
			.status{
				font-size: 14px;
				color: #fd9540;
			}
		}
		.list-body{
			font-size: 12px;
			margin-bottom: 3px;
			view{
				padding-top: 3px;
				span{
					margin-left: 10px;
				}
			}
		}
		
	}
}
</style>
